package ProjectoX;

import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;

public abstract class Componente {

	protected Posicion Pos;
	protected String [] NombresSprite;
	protected int FrameActual;
	protected int frameSpeed;
	protected int t;
	protected int Columna;
	protected int Fila;
	protected Nivel miNivel;
	protected SpriteCache spriteCache;
	protected int Localization;
	
	public Componente (Nivel N, Posicion P, int Fila, int Columna) {
		miNivel = N;
		Pos = P;
		this.Columna = Columna;
		this.Fila = Fila;
		spriteCache = miNivel.getSpriteCache();
		FrameActual = 0;
		frameSpeed = 1;
		t = 0;
	}
	
	public Rectangle getBounds() {
		return new Rectangle(Pos.getX(),Pos.getY(),Pos.getAncho(),Pos.getAlto());
	}
	
	public void setLocalization(int q) {
		Localization = q;
	}
	
	public void paint(Graphics2D g){
		g.drawImage( spriteCache.getSprite(NombresSprite[FrameActual]), Localization,Pos.getY(), miNivel );
	}
	
	public void setSpriteName(String [] names) { 
		NombresSprite = names;
		Pos.setAlto(0);
		Pos.setAncho(0);
		for (int i = 0; i<names.length; i++) {
			BufferedImage image = spriteCache.getSprite(NombresSprite[i]);
			Pos.setAlto(Math.max(Pos.getAlto(), image.getHeight()));
			Pos.setAncho(Math.max(Pos.getAncho(), image.getWidth()));
		}
	}   
	
	public void setFrameSpeed(int i) {
		frameSpeed = i; 
	}
	
	public int getFrameSpeed() {
		return frameSpeed; 
	}
	
	public Posicion getPos() {
		return Pos;
	}
	
	public int getFila() {
		return Fila;
	}
	
	public int getColumna() {
		return Columna;
	}

}
